package com.dream.mqpushserver.netty;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class MyProtocolEnCoder extends MessageToByteEncoder<Request> {

    @Override
    protected void encode(ChannelHandlerContext ctx, Request request, ByteBuf out) throws Exception {

        System.out.println("encode request ... ");
        if (request == null) {
            throw new RuntimeException("request is null ");
        }
        out.writeByte(request.getType());
        out.writeInt(request.getLength());
        out.writeBytes(request.getContent().getBytes());
    }
}
